package com.jayhuang.user_center.exception;

import com.jayhuang.user_center.common.ErrorCode;
import com.jayhuang.user_center.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler{

    @ExceptionHandler(BusinessException.class)
    public Result handleBusinessException(BusinessException e) {
        return Result.error(e.getCode(), e.getMessage(),e.getDescription());
    }

    @ExceptionHandler(Exception.class)
    public Result exception(Exception e){
        log.error("RuntimeException", e);
        return Result.error(ErrorCode.SYSTEM_ERROR, e.getMessage());
    }
}
